#!/usr/bin/env python
#
# Copyright 2011 Justin Bruce Van Horne <justinvh@gmail.com>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Handles the loading of material files.

 Material: Class for handling materials
"""

import pyglet

class MaterialImage:
    image = None
    config = {}

    def __init__(self, image):
        self.image = image
        #self.image = pyglet.image.Texture(self.image)


class Material:
    """A material is simply a definition of a texture that can be
    reused in the engine."""
    tiles = []

    def __init__(self, config, name, batch=pyglet.graphics.Batch()):
        self.batch = batch
        self.image = pyglet.image.load("game/%s" % config['texture'])
        self.image = pyglet.image.TileableTexture.create_for_image(self.image)
        self.name = name
        self.config = config
        self.scale = 1.0

    def delete(self):
        pass

    def spawn(self, x, y):
        """Spawn a tile at a certain x, y"""
        s = pyglet.sprite.Sprite(self.image, x, y, batch=self.batch)
        s.scale = self.scale
        self.tiles.append(s)
        return s
